// pages/componentSm/hottest/hottest.js
const app = getApp();
import getApi from "../../../utils/api.js"
let imgUrl = app.globalData.imgUrl;
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },
  options: {
    addGlobalClass: true,
  },
  attached (){
    this.gethot3()
  },

  /**
   * 组件的初始数据
   */
  data: {
    scrollLeft:0,  //最热TOP3滚动条距离左边的位置
    speed:100, //滚动条每次滚动的距离
    isRightScroll:true,  //滚动条是否可以向右滚动
    isScroll:false,  //滚动条是否可以两边都能滚动
    scrollRight:0, //滚动条滚到底时scroll-left的值
    hotList:[
      // {
      //   "img":imgUrl + '1.jpg',
      //   "title":"日本文件再次对中国军事安全动向表担忧日本文件再次对中国军事安全动向表担忧"
      // },
      // {
      //   "img": imgUrl + '1.jpg',
      //   "title": "日本文件再次对中国军事安全动向表担忧日本文件再次对中国军事安全动向表担忧"
      // },
      // {
      //   "img": imgUrl + '1.jpg',
      //   "title": "日本文件再次对中国军事安全动向表担忧日本文件再次对中国军事安全动向表担忧"
      // }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //最热TOP3点击向左箭头时scroll-view的滚动条向左滚动
    hotToLeft(){
      let { scrollLeft, speed, isRightScroll, scrollRight } = this.data;
      if (!isRightScroll){
        scrollLeft -= speed;
        if(scrollLeft <= 0){
          this.setData({
            isRightScroll: true,
            scrollLeft: 0
          })
        } else if (scrollLeft > 0){
          this.setData({
            isScroll:true
          })
        }
        this.setData({
          scrollLeft
        })
      }

      console.log(scrollLeft);
    },
    //最热TOP3点击向右箭头时scroll-view的滚动条向右滚动
    hotToRight(){
      let { scrollLeft, speed, isRightScroll } = this.data;
      if (isRightScroll) {
        scrollLeft += speed;
        this.setData({
          scrollLeft
        })
      }
      console.log(scrollLeft);
    },
    //滚动到最左边
    leftMost(){
      let { isRightScroll, scrollLeft} = this.data;
      this.setData({
        isRightScroll:true,
        isScroll: false,
        scrollLeft:0
      })
    },
    //滚动到最右边
    rightMost(e){
      let { isRightScroll,scrollLeft,scrollRight } = this.data;
      scrollRight = scrollLeft
      this.setData({
        isRightScroll: false,
        isScroll:false,
        scrollRight
      })
    },
    //监听滚动条的位置
    bindSl(e){
      this.setData({
        scrollLeft:e.detail.scrollLeft
      })
    },
    gethot3() {
      let that = this
      wx.request({
        url: getApi.getHotlist,
        data: {},
        header: { 'Content-Type': 'application/json' },
        success: function (res) {
          let hot_info3 = res.data.data.hot_info
          that.setData({
            hotList: hot_info3
          })
        },
        fail(err) {
          console.log(err)
        }
      })

    }
  }
})
